import { uploadType } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			uploadTip: '菜品图片',
			tip: '',
			prop: 'pic',
			type: 'upload',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
			rules: [{ required: true, message: '请上传菜品图片' }],
		},
		{
			label: '菜品名称',
			prop: 'dishName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 24,
			rules: [{ required: true, message: '请输入菜品名称' }],
		},
		{
			label: '菜品分类',
			prop: 'dishType',
			propName: 'dishTypeLabel',
			type: 'remoteSelect',
			code: 'DISH_TYPE',
			api: 'getDictItemList',
			dataType: 'string',
			filterKey: 'value',
			multiple: false,
			span: 24,
			rules: [{ required: true, message: '请选择菜品分类' }],
		},
		{
			label: '价格（元）',
			prop: 'price',
			type: 'number',
			min: 0,
			max: 100000,
			controlsPosition: 'right',
			span: 12,
			rules: [{ required: true, message: '请输入价格（元）' }],
		},

		{
			label: '单位',
			prop: 'quantifier',
			span: 12,
			type: 'select',
			dicData: [
				{
					label: '份',
					value: '份',
				},
				{
					label: '个',
					value: '个',
				},
			],
			rules: [{ required: true, message: '请选择单位' }],
		},
		{
			label: '状态',
			prop: 'state',
			type: 'radio',
			defaultValue: 0,
			dicData: [
				{
					label: '在售',
					value: 0,
				},
				{
					label: '停售',
					value: 1,
				},
			],
			rules: [{ required: true, message: '请选择状态' }],
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '组织机构名称',
			prop: 'orgName',
			type: 'input',
			span: 8,
		},
		{
			label: '组织机构所在区',
			prop: 'unitAreas',
			propName: 'unitAreasName',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '菜品名称',
			prop: 'dishName',
			type: 'input',
			span: 8,
		},
		{
			label: '状态',
			prop: 'state',
			type: 'select',
			dicData: [
				{
					label: '在售',
					value: 0,
					type: 'success',
				},
				{
					label: '停售',
					type: 'danger',
					value: 1,
				},
			],
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '组织机构名称', prop: 'orgName' },
		{ label: '组织机构所在区', prop: 'orgArea' },
		{
			label: '菜品图片',
			custome: 'file',
			prop: 'pic',
		},
		{ label: '菜品名称', prop: 'dishName' },
		{ label: '价格/元', prop: 'price' },
		{ label: '单位', prop: 'quantifier' },

		{
			label: '状态',
			prop: 'state',
			custome: 'tag',
			dicData: [
				{
					label: '在售',
					value: 0,
					type: 'success',
				},
				{
					label: '停售',
					type: 'danger',
					value: 1,
				},
			],
		},
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omDish_page',
	add: 'view_omDish_add',
	edit: 'view_omDish_edit',
	delete: 'view_omDish_del',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '菜品管理',
	dictcodes: ['DISH_TYPE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'dishName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
	beforeOnLoadFormate: async (params) => {
		if (params.unitAreasName) {
			const tempArea = params.unitAreasName.split('/')
			params.orgArea = tempArea[tempArea.length - 1]
		}
		const queryObj = {
			...params,
			unitAreas: undefined,
			unitAreasName: undefined,
		}
		return Promise.resolve(queryObj)
	},
}
